<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="18">
            <a-col :md="6" :sm="24">
              <a-form-item label="时间">
                <a-range-picker
                  :value="valueDate"
                  @change="onChangeData"
                />
              </a-form-item>
            </a-col>
            <a-col :md="!advanced && 4 || 24" :sm="24">
              <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="reset">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="table-page-search-wrapper">
        <div style="font-size: 16px;">
          <span v-if="start_time">{{this.start_time}}到{{this.end_time}}</span>总佣金：<span class="red">{{this.sum.toFixed(2)}}</span>元
        </div>
      </div>
      <s-table
        ref="table"
        size="default"
        :rowKey="(record,index)=>{return index}"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="statusname" slot-scope="text, record">
          <span>{{record.statusname}}</span>
        </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { STable } from '@/components'
import api from '@/api/product.js'
// import StepByStepModal from './modules/StepByStepModal'

const columns = [
  {
    title: '编号',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '订单编号',
    dataIndex: 'id'
  },
  {
    title: '时间',
    dataIndex: 'createtime',
  },
  {
    title:'业务员',
    dataIndex:'username'
  },
  // {
  //   title: '供应商',
  //   dataIndex: 'gys',
  // },
  // {
  //   title: '下单商户',
  //   dataIndex: 'merchant',
  // },
  {
    title:'来源',
    dataIndex:'reason'
  },
  {
    title: '佣金',
    dataIndex: 'balance',
  },
  // {
  //   title: '操作',
  //   dataIndex: 'action',
  //   width: '250px',
  //   scopedSlots: { customRender: 'action' }
  // }
]
export default {
  components: {
    STable,
  },
  data () {
    this.columns = columns
    return {
      sum:0,
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      loadData: parameter => {
        this.queryParam = {
          user_id:this.$route.query.user_id,
          createtime:this.start_time,
          endtime:this.end_time
        }
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        console.log('requestParameters',requestParameters)
        return api.WorkbalPage(requestParameters).then(res => {
          if(requestParameters.pageNo==1){
            this.sum = res.data.sum;
          }
          this.$forceUpdate()
          console.log('this.sum',this.sum)
          return res.data
        })
      },
      start_time:'',
      end_time:'',
      all_time:'',
      valueDate:[null, null],
      dateString:''
    }
  },
  computed: {
    
  },
  created() {
    // 部门查询
    //this.DepartmentList()
    // 角色查询
    // this.RoLeList()
    // if(localStorage.getItem('user_type') == 2) {
    //   this.userShow = true
    // }
    // this.getRoleList()
    // this.getYWYID()
  },
  mounted() {
    console.log('mounted__valueDate',this.valueDate)
  },
  methods: {
    moment,
    // 选择时间
    onChangeData (date, dateString) {
      console.log('dateString',dateString)
      console.log('valueDate',this.valueDate)
      this.valueDate = date;
      this.dateString = dateString
      this.start_time = dateString[0]
      this.end_time = dateString[1]
      this.$refs.table.refresh(true)
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    // 重置
    reset () {
      // const form = this.$refs.createModal.form
      this.queryParam = {}
      this.start_time = ''
      this.end_time = ''
      this.valueDate = [null, null]
        // 重置表单数据
      // form.resetFields()
      // 刷新表格
      this.$refs.table.refresh()
    }
  }
  
}
</script>
